{{#if @model.canLoadMore}}
  {{hide-application-footer}}
{{/if}}

{{#if this.redirectedReason}}
  <div class="alert alert-info">{{this.redirectedReason}}</div>
{{/if}}

{{#if @model.sharedDrafts}}
  <TopicList
    @listTitle="shared_drafts.title"
    @top={{this.top}}
    @hideCategory="true"
    @category={{@category}}
    @topics={{@model.sharedDrafts}}
    @discoveryList={{true}}
    class="shared-drafts"
  />
{{/if}}

<DiscoveryTopicsList
  @model={{@model}}
  @incomingCount={{this.topicTrackingState.incomingCount}}
  @bulkSelectHelper={{@bulkSelectHelper}}
>
  {{#if this.top}}
    <div class="top-lists">
      <PeriodChooser
        @period={{@period}}
        @action={{@changePeriod}}
        @fullDay={{false}}
        class="cus-top-chooser"
      />
    </div>
  {{else}}
    {{#if (or this.topicTrackingState.hasIncoming @model.loadingBefore)}}
      <div class="show-more {{if this.hasTopics 'has-topics'}}">
        <a
          tabindex="0"
          href
          {{on "click" this.showInserted}}
          class="alert alert-info clickable
            {{if @model.loadingBefore 'loading'}}"
        >
          <CountI18n
            @key="topic_count_"
            @suffix={{this.topicTrackingState.filter}}
            @count={{or
              @model.loadingBefore
              this.topicTrackingState.incomingCount
            }}
          />
          {{#if @model.loadingBefore}}
            {{loading-spinner size="small"}}
          {{/if}}
        </a>
      </div>
    {{/if}}
  {{/if}}

  {{#if this.renderNewListHeaderControls}}
    <NewListHeaderControlsWrapper
      @current={{@model.params.subset}}
      @newRepliesCount={{this.newRepliesCount}}
      @newTopicsCount={{this.newTopicsCount}}
      @changeNewListSubset={{@changeNewListSubset}}
    />
  {{/if}}

  <span>
    <PluginOutlet
      @name="before-topic-list"
      @connectorTagName="div"
      @outletArgs={{hash category=@category tag=@tag}}
    />
  </span>

  {{#if this.hasTopics}}
    <TopicList
      @highlightLastVisited={{true}}
      @top={{this.top}}
      @hot={{this.hot}}
      @showTopicPostBadges={{this.showTopicPostBadges}}
      @showPosters={{true}}
      @canBulkSelect={{@canBulkSelect}}
      @bulkSelectHelper={{@bulkSelectHelper}}
      @changeSort={{@changeSort}}
      @hideCategory={{@model.hideCategory}}
      @order={{this.order}}
      @ascending={{this.ascending}}
      @expandGloballyPinned={{this.expandGloballyPinned}}
      @expandAllPinned={{this.expandAllPinned}}
      @category={{@category}}
      @topics={{@model.topics}}
      @discoveryList={{true}}
      @focusLastVisitedTopic={{true}}
      @showTopicsAndRepliesToggle={{this.showTopicsAndRepliesToggle}}
      @newListSubset={{@model.params.subset}}
      @changeNewListSubset={{@changeNewListSubset}}
      @newRepliesCount={{this.newRepliesCount}}
      @newTopicsCount={{this.newTopicsCount}}
    />
  {{/if}}
  <span>
    <PluginOutlet
      @name="after-topic-list"
      @connectorTagName="div"
      @outletArgs={{hash category=@category tag=@tag}}
    />
  </span>
</DiscoveryTopicsList>

<footer class="topic-list-bottom">
  <ConditionalLoadingSpinner @condition={{@model.loadingMore}} />
  {{#if this.allLoaded}}
    <PluginOutlet
      @name="topic-list-bottom"
      @outletArgs={{hash
        category=@category
        tag=@tag
        allLoaded=this.allLoaded
        model=@model
      }}
    >
      <TopicDismissButtons
        @position="bottom"
        @selectedTopics={{@bulkSelectHelper.selected}}
        @model={{@model}}
        @showResetNew={{@showResetNew}}
        @showDismissRead={{@showDismissRead}}
        @resetNew={{@resetNew}}
        @dismissRead={{@dismissRead}}
      />

      <FooterMessage
        @education={{this.footerEducation}}
        @message={{this.footerMessage}}
      >
        {{#if @tag}}
          {{html-safe
            (i18n "topic.browse_all_tags_or_latest" basePath=(base-path))
          }}
        {{else if this.latest}}
          {{#if @category.canCreateTopic}}
            <DiscourseLinkedText
              @action={{fn
                this.composer.openNewTopic
                (hash category=@category preferDraft=true)
              }}
              @text="topic.suggest_create_topic"
            />
          {{/if}}
        {{else if this.top}}
          {{html-safe
            (i18n
              "topic.browse_all_categories_latest_or_top" basePath=(base-path)
            )
          }}
          <TopPeriodButtons @period={{@period}} @action={{@changePeriod}} />
        {{else}}
          {{html-safe
            (i18n "topic.browse_all_categories_latest" basePath=(base-path))
          }}
        {{/if}}
      </FooterMessage>
    </PluginOutlet>
  {{/if}}
</footer>